<template>
  <el-form
    ref="editForm"
    label-width="80px"
    size="small"
    :model="editEntity"
    :rules="formRule"
  >
    <el-form-item
      :label="L('TenancyName')"
      prop="tenancyName"
    >
      <el-input
        v-model="editEntity.tenancyName"
        :maxlength="32"
        :minlength="2"
      />
    </el-form-item>
    <el-form-item
      :label="L('Name')"
      prop="name"
    >
      <el-input
        v-model="editEntity.name"
        :maxlength="32"
        :minlength="2"
      />
    </el-form-item>
    <el-form-item>
      <el-checkbox v-model="editEntity.isActive">{{ L('IsActive') }}</el-checkbox>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  name: 'CreateOrEdit',
  props: {
    entity: {
      type: Object,
      default: () => { return {} }
    }
  },
  data() {
    return {
      editEntity: {},
      formRule: {
        name: [{ required: true, message: this.L('FieldIsRequired', undefined, this.L('TenantName')), trigger: 'blur' }],
        tenancyName: [{ required: true, message: this.L('FieldIsRequired', undefined, this.L('TenancyName')), trigger: 'blur' }]
      }
    }
  },
  computed: {
    permissions() {
      // 打开user界面已经初始化过了
      return this.$store.state.role.permissions
    }
  },
  watch: {
    entity(val) {
      this.editEntity = val
    }
  },
  created() {
    this.editEntity = this.entity
  },
  methods: {
    clearValidate() {
      this.$refs.editForm.clearValidate()
    },
    validate(cb) {
      this.$refs.editForm.validate(cb)
    }
  }
}
</script>
